package de.shortys.myhome.api.view.event;

import java.awt.Dimension;

import javax.swing.JComponent;
import javax.swing.SwingUtilities;

public class ComponentExpandingEvent extends ViewEvent {

	private JComponent comp;
	private int maxHeight = 0;
	private int minHeight = 0;

	public ComponentExpandingEvent(JComponent comp) {
		this.comp = comp;
	}

	@Override
	protected void execute() {
		for (int i = minHeight; i <= maxHeight; i++) {
			comp.setPreferredSize(new Dimension(0, i));
			SwingUtilities.invokeLater(new Runnable() {
				@Override
				public void run() {
					comp.revalidate();
					comp.repaint();
				}
			});

			try {
				Thread.sleep(2);
			} catch (InterruptedException e) {
			}
		}
	}

	public void setMaxHeight(int maxHeight) {
		this.maxHeight = maxHeight;
	}

	public void setMinHeight(int minHeight) {
		this.minHeight = minHeight;
	}

}
